package com.sm.service;

import java.util.List;

import com.sm.model.SearchHistory;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sm.dao.SearchHistoryMapper;

@Service
public class SearchHistoryService {
	
	@Autowired
	private SearchHistoryMapper searchHistoryMapper;
	
	/**
	 *	将搜索记录插入数据库
	 * @param searchHistory
	 * @return
	 */
	public int insertSelective(SearchHistory searchHistory) {
		return searchHistoryMapper.insertSelective(searchHistory);
	}
	
	/**
	 *	根据用户id查询其搜索记录。
	 * @param userId	用户id
	 * @return
	 */
	public List<SearchHistory> selectsearchByUserId(Integer userId){
		List<SearchHistory> searchHistorys = searchHistoryMapper.selectsearchByUserId(userId);
		return searchHistorys;
	}
	
	/**
	 *	更新搜索历史。
	 * @param searchHistory
	 * @return
	 */
	public int updateByPrimaryKeySelective(SearchHistory searchHistory) {
		int count = searchHistoryMapper.updateByPrimaryKeySelective(searchHistory);
		return count;
	}
	
	/**
	 *	根据历史记录id删除某一条历史记录。
	 * @param searchHistoryId	历史记录id
	 * @return
	 */
	public int deleteByPrimaryKey(Integer searchHistoryId) {
		int count = searchHistoryMapper.deleteByPrimaryKey(searchHistoryId);
		return count;
	}
	
	
	/**
     *	根据用户id清除所有的历史记录
     * @param userId	用户id
     * @return
     */
    public int clearSearchByUserId(@Param("userId")Integer userId) {
    	int count = searchHistoryMapper.clearSearchByUserId(userId);
		return count;
    }

}
